﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WebResource
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                txtOutPut.Text = dialog.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {//执行
            string dir = txtOutPut.Text;
            string template = comboBox2.Text;
            string nameSpace = txt_namespace.Text;
            if (dir.Length == 0) MessageBox.Show("请选择指定路径！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            if (template.Length == 0) MessageBox.Show("请指定生成模板！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            if (nameSpace.Length == 0) MessageBox.Show("请指定命名空间！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            DirectoryInfo Dir = new DirectoryInfo(dir);
            int num = 0;
            StringBuilder temp = new StringBuilder();
            foreach (FileInfo accounts in Dir.GetFiles()) //查找文件  
            {
                num++;
                string tempName = nameSpace + accounts.Name;
                switch (template)
                { 
                    case"js":
                        temp.AppendLine("[assembly: WebResource(" + tempName + ", \"text/javascript\")]");
                        break;
                    case "css":
                        temp.AppendLine("[assembly: WebResource(\""+tempName+"\", \"text/css\", PerformSubstitution = true)]");
                        break;
                    case "img":
                        temp.AppendLine("[assembly: WebResource(\"" + tempName + "\", \"image/gif\")]");
                        break;
                }
            }
            txtContent.Text = temp.ToString();
        }
    }
}
